package org.taobao.ibatiside.ui.wizard;

import java.util.List;

import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.taobao.ibatiside.ui.util.ClassField;

public class ShowParameterClassInfoComposite extends Composite {
	private Text text;
	private Table table;
	private TableViewer tableViewer;
	public static final class ClassFieldLabelProvider extends LabelProvider implements ITableLabelProvider{
		@Override
		public Image getColumnImage(Object element, int columnIndex) {
			return null;
		}

		@Override
		public String getColumnText(Object element, int columnIndex) {
			ClassField f = (ClassField) element;
			return columnIndex == 0? f.getFieldName() : columnIndex == 1 ? String.valueOf(f.isSetExisted()) : String.valueOf(f.isGetExisted());
		}
		
	}

	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public ShowParameterClassInfoComposite(Composite parent, int style) {
		super(parent, style);
		setLayout(new GridLayout(1, false));
		
		Composite composite = new Composite(this, SWT.NONE);
		composite.setLayout(new RowLayout(SWT.HORIZONTAL));
		GridData gd_composite = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
		gd_composite.heightHint = 30;
		composite.setLayoutData(gd_composite);
		
		Label lblClass = new Label(composite, SWT.NONE);
		lblClass.setAlignment(SWT.RIGHT);
		lblClass.setLayoutData(new RowData(58, SWT.DEFAULT));
		lblClass.setText("Class");
		
		text = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		text.setLayoutData(new RowData(314, SWT.DEFAULT));
		
		tableViewer = new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION);
		table = tableViewer.getTable();
		table.setLinesVisible(true);
		table.setHeaderVisible(true);
		table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
		TableColumn tblclmnFieldName = tableViewerColumn.getColumn();
		tblclmnFieldName.setWidth(216);
		tblclmnFieldName.setText("Field Name");
		
		TableViewerColumn tableViewerColumn_1 = new TableViewerColumn(tableViewer, SWT.NONE);
		TableColumn tblclmnWrite = tableViewerColumn_1.getColumn();
		tblclmnWrite.setWidth(102);
		tblclmnWrite.setText("Write");
		
		TableViewerColumn tableViewerColumn_2 = new TableViewerColumn(tableViewer, SWT.NONE);
		TableColumn tblclmnRead = tableViewerColumn_2.getColumn();
		tblclmnRead.setWidth(107);
		tblclmnRead.setText("Read");
		tableViewer.setContentProvider(new ArrayContentProvider());
		tableViewer.setLabelProvider(new ClassFieldLabelProvider());

	}
	public void setClassFQN(String fqn){
		text.setText(fqn);
	}
	public void setFields(List<ClassField> fields){
		tableViewer.setInput(fields);
	}
	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
}
